package stacks_and_queues;

import java.util.Stack;

public class MyQueue {
    Stack s1;
    Stack s2;
    public MyQueue() {
        s1 = new Stack();
        s2 = new Stack();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        int size = s1.size();
        while (size > 1){
            s2.push(s1.pop());
        }
        int tep = (int)s1.pop();
        while (!s2.empty()){
            s1.push(s2.pop());
        }
        return tep;
    }

    public int peek() {
        int size = s1.size();
        int tep = 0;
        while (size > 0){
            if(size == 1){
                tep = (int)s1.pop();
            }else {
            s2.push(s1.pop());
            }
        }

        while (!s2.empty()){
            s1.push(s2.pop());
        }
        return tep;
    }

    public boolean empty() {
        return !s1.empty() && !s2.empty();
    }
    public int size(){
        int size = 0;
        while (!s1.empty()){
            size++;
        }
        return size;
    }

}
